package p2pcdnsim.cdn;


import p2pcdnsim.exception.CacheClassInstantiationException;
import p2pcdnsim.exception.ClientDoesNotExistException;
import p2pcdnsim.exception.NodeUnexistentException;
import p2pcdnsim.exception.SurrogateAlreadyInsertedException;
import desmoj.core.simulator.Model;

public class CDNConstructor {

	Model model;
	private CDNBuilder builder;
	
	
	public void setModel(Model model) {
		this.model = model;
	}
	
	public void setBuilder(CDNBuilder builder) {
		this.builder = builder;
	}

	public CDN getCDN() {
		return builder.getCDN();
	}

	public void constructCDN() throws NodeUnexistentException, CacheClassInstantiationException, SurrogateAlreadyInsertedException, ClientDoesNotExistException {
		builder.createNewCDN(model);
		System.out.println("CDN: Create and place origin server.");
		builder.createAndPlaceOriginServer();
		System.out.println("CDN: Create and place request redirector.");
		builder.createAndPlaceRequestRedirector();
		System.out.println("CDN: Define client placement.");
		builder.defineClientPlacement();
		System.out.println("CDN: Create and place surrogates.");
		builder.createAndPlaceSurrogates();
		System.out.println("CDN: Insert requests.");
		builder.insertClientRequests();
	}

}
